package com.qzdsoft.erpcloud.service.basic.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.qzdsoft.erpcloud.domain.basic.DataDictionaryType;
import com.qzdsoft.erpcloud.mapper.basic.DataDictionaryTypeMapper;
import com.qzdsoft.erpcloud.service.basic.DataDictionaryTypeService;
import com.qzdsoft.erpcloud.vo.query.basic.DataDictionaryTypeInfo;
import com.qzdsoft.utils.constant.SystemConstant;
import com.qzdsoft.vo.LayTableResponse;
import com.qzdsoft.vo.Response;
import com.qzdsoft.vo.ResultEnum;

/**
 * Created by Admin
 */
@Service
public class BasicDataDictionaryTypeServiceImpl implements DataDictionaryTypeService {

    @Autowired
    private DataDictionaryTypeMapper basicDataDictionaryTypeMapper;

    @Override
    public DataDictionaryType selectById(Integer id) {
        return basicDataDictionaryTypeMapper.selectByPrimaryKey(id);
    }

    @Override
    public Response<String> saveOrUpd(DataDictionaryType basicDataDictionaryType) {
        if(null == basicDataDictionaryType.getCompany_id()){
            basicDataDictionaryType.setCompany_id(SystemConstant.companyIdGg);
        }
        if(null != basicDataDictionaryType.getId()){
            basicDataDictionaryTypeMapper.updateByPrimaryKey(basicDataDictionaryType);
        } else {
            basicDataDictionaryType.setCtime(new Date());
            basicDataDictionaryTypeMapper.insert(basicDataDictionaryType);
        }
        return new Response<String>(ResultEnum.SUCCESS);
    }

    @Override
    public Response<String> del(Integer id) {
        basicDataDictionaryTypeMapper.deleteByPrimaryKey(id);
        return new Response<String>(ResultEnum.SUCCESS);
    }


    @Override
    public LayTableResponse<DataDictionaryTypeInfo> selectData(String name, String decode, Integer companyId, Integer isPreinstall, Integer start, Integer pageSize) {
        PageHelper.startPage(start, pageSize);
        List<DataDictionaryTypeInfo> list = basicDataDictionaryTypeMapper.selectData(name, decode, companyId, isPreinstall, start, pageSize);
        return new LayTableResponse<DataDictionaryTypeInfo>(list);
    }

    @Override
    public List<DataDictionaryType> selectAll() {
        return basicDataDictionaryTypeMapper.selectAll();
    }
}
